
@extends('layout.app')

@section('title', '绑定账号')

@section('content')
    <style>
        div.weui_extra_area a {
            margin: 0 10px;
        }
        .footer-content {
            font-size: 13px;
            color: #adb3c9;
        }
        .footer-wrap {
            width: 100%;
            text-align: center;
            position: fixed;
            bottom: 20px;
        }
    </style>
    <div class="weui_cells weui_cells_form">
        <form action="{{ url('user/bind') }}" method="post">
            {!! csrf_field() !!}
            <input type="hidden" name="RadioButtonList1" value="%D1%A7%C9%FA">
            <input type="hidden" name="Button1" value="">
            <input type="hidden" name="lbLanguage" value="">
            <input type="hidden" name="hidPdrs" value="">
            <input type="hidden" name="hidsc" value="">
            <input type="hidden" name="cookieId" value="{{ $cookieId }}">
            <input type="hidden" name="sessionId" value="{{ $sessionId }}">
            <input type="hidden" name="__VIEWSTATE" value="{{ $viewState }}">
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">学号</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input name="txtUserName" class="weui_input" type="number" placeholder="{{ date('Y') . '30098000' }}">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">密码</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input name="TextBox2" class="weui_input" type="password" placeholder="请输入教务系统密码">
                </div>
            </div>
            <div class="weui_cell weui_vcode">
                <div class="weui_cell_hd"><label class="weui_label">验证码</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input name="txtSecretCode" class="weui_input" type="text" placeholder="请输入验证码">
                </div>
                <div class="weui_cell_ft">
                    <img id="code" src="{{ url('user/code', [$sessionId]) }}/1/{{ $cookieId }}" alt="验证码" onClick="this.src='{{ url('user/code', [$sessionId]) }}/' + Math.random() + '/{{ $cookieId }}'">
                </div>
            </div>
        </form>
    </div>
    <button id="submit" class="weui_btn weui_btn_primary" style="margin-top: 20px;width: 80%;">确认绑定</button>
    <div class="footer-wrap">
        <span class="footer-content">&copy;2016&nbsp;华广计算机协会&nbsp;</span>
        <a href="javascript:;" class="open-popup footer-content" data-target="#agreement"><u>使用前必读</u></a>
    </div>
    @include('app.user.contract')
@endsection

@section('js')
    <script>
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        $("#submit").click(function(){
            if($("input[name='txtUserName']").val() == '' || $("input[name='TextBox2']").val() == ''){
                $.toast('请输入账号和密码', "cancel");
                return;
            }
            if($("input[name='txtSecretCode']").val() == ''){
                $.toast('请输入验证码', "cancel");
                return;
            }
            $.showLoading("正在绑定");
            $.ajax({
                type: "POST",
                url: "{{ url('user/bind') }}",
                dataType: "json",
                data: $("form").serialize(),
                success: function(data){
                    $.hideLoading();
                    if(data.msg == 'ok'){
                        $.toast("绑定成功");
                        if(data.target != ''){
                            setTimeout(function(){
                                window.location.href = data.target;
                            }, 2000);
                        }
                    }else{
                        $.toast(data.msg, "forbidden");
                        document.getElementById('code').click();
                    }
                }
            })
        });
    </script>
@endsection